<template>
  <div class="bg-white-height" v-if="route.meta.title != '首页' && route.meta.title != '商品列表'"></div>
  <van-nav-bar v-if="showNavbar" :title="(route.meta.title as string)" left-text="" left-arrow
    @click-left="router.back()" />
  <router-view />
  <div class="home_loading is_home_loading"></div>
</template>

<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";

const route = useRoute();
const router = useRouter();
const showNavbar = computed(() => {
  return route.meta.showNavbar;
});
const cannotReturn = ref([
  // 登录
  '/login',

  // 招商部
  '/home/index',
  '/productList',
  '/supplierList',
  '/productSelection',

  // 产品部
  '/productHome/page',
  '/productHome/productLists',
  '/productHome/revenue',
  '/productHome/productMine',

  // 核价部
  '/approval',
  '/pendingApproval/待处理',
  '/pendingApproval/已通过',
  '/pendingApproval/已驳回',
  // 品控部
  '/qualityControl',
  '/pendingQualityControl/待处理',
  '/pendingQualityControl/已通过',
  '/pendingQualityControl/已驳回',
  // 运营部
  '/operation/operatepage',
  '/operation/selectedProducts',
  '/operation/salesList',
  '/operation/operateMine',
  // 选品官
  '/selection/selectionOfficer',
  '/selection/selectionProducts',
  '/selection/selectionSalesList',
  '/selection/selectionOperateMine',
  // 研发部
  '/research/researchPage',
  '/research/researchLists',
  '/research/researchRevenue',
  '/research/mine',
  // ios专属审核账号
  '/forge/forgeHome',
  '/forge/forgeAdd',
  '/forge/forgeMy'
])
watch(() => router.currentRoute.value, (v) => {
  // 首页不可返回
  if (cannotReturn.value.indexOf(v.fullPath) !== -1) {
    (window as any).uni.webView.postMessage({
      data: {
        type: '0'
      }
    })
  } else {
    (window as any).uni.webView.postMessage({
      data: {
        type: '1'
      }
    })
  }
}, { immediate: true });

import { userStore } from "@/store/user";
import { storeToRefs } from "pinia";
const store = userStore();
const { user } = storeToRefs(store);
/** 自定义手势左滑回退事件 */
(window as any).fallback = function (arg) {
  if (arg.action == 'back') {
    // 出库列表
    if (router.currentRoute.value.fullPath.indexOf("finishedGoods") !== -1) {
      router.push({
        path: '/addOutbound',
        query: {
          coreId: route.query.coreId,
          index: route.query.index
        }
      })
      // 新增出库缓存列表
    } else if (router.currentRoute.value.fullPath.indexOf("addOutbound") !== -1) {
      router.push({
        path: '/selectAnchor',
        query: {
          index: route.query.index
        }
      })
      // 清除缓存
      localStorage.removeItem('outboundList')
      localStorage.removeItem('outboundsId')
      localStorage.removeItem('totalList')
      localStorage.removeItem('outImageList')
      // 选择库存单
    } else if (router.currentRoute.value.fullPath.indexOf("associatedInventory") !== -1) {
      router.push({
        path: '/addArehousing',
        query: {
          types: 'left',
          index: route.query.index,
          info: JSON.stringify({}),
        }
      })
      // 新增入库
    } else if (router.currentRoute.value.fullPath.indexOf("addArehousing") !== -1) {
      router.push('/storageType')
      // 清除缓存
      localStorage.removeItem('warehouseList')
      localStorage.removeItem('warehouseIndex')
      localStorage.removeItem('relatedDocumentsId')
      localStorage.removeItem('totalList')
      localStorage.removeItem('evidenceList')
      localStorage.removeItem('storesId')
      // 出库类型
    } else if (router.currentRoute.value.fullPath == '/outboundType') {
      router.push('/productHome')
      // 选择电商部门
    } else if (router.currentRoute.value.fullPath.indexOf("selectAnchor") !== -1) {
      router.push('/outboundType')
      // 入库类型
    } else if (router.currentRoute.value.fullPath.indexOf("storageType") !== -1) {
      router.push('/productHome')
      // 盘点调拨操作类型
    } else if (router.currentRoute.value.fullPath.indexOf("inventoryAllocation") !== -1) {
      router.push('/productHome')
      // 盘点库位商品
    } else if (router.currentRoute.value.fullPath.indexOf("inventoryCommodity") !== -1) {
      if (router.currentRoute.value.query.details) {
        router.back()
      } else {
        router.push('/inventoryAllocation')
        localStorage.removeItem("stocktakingList");
        localStorage.removeItem("shelvesCodeList");
        localStorage.removeItem("stocktakingIdList");
        localStorage.removeItem("countId");
      }
      // 盘点库位商品选择商品
    } else if (router.currentRoute.value.fullPath.indexOf('inventoryGoods') !== -1) {
      router.push({
        path: '/inventoryCommodity',
      })
      // 更换货架
    } else if (router.currentRoute.value.fullPath.indexOf("allocation") !== -1) {
      router.push('/inventoryAllocation')
      localStorage.removeItem("allocateList");
      localStorage.removeItem("allocateIdList");
      localStorage.removeItem("allocateShelves");
      localStorage.removeItem("allocationName");
      // 盘点完成
    } else if (router.currentRoute.value.fullPath.indexOf('inventorySuccessful') !== -1) {
      router.push((router.currentRoute.value.query.from as any))
      // 调拨成功
    } else if (router.currentRoute.value.fullPath.indexOf('transferSuccessful') !== -1) {
      router.push('/allocation')
    } else if (router.currentRoute.value.fullPath.indexOf('inventoryRecord') !== -1) {
      router.push('/productHome/revenue')
    } else if (router.currentRoute.value.fullPath.indexOf('addSupplierClassAdd') !== -1) {
      router.push('/addSupplierClass')
    } else if (router.currentRoute.value.fullPath.indexOf('addSupplierClass') !== -1) {
      router.push('/addSupplier')
    } else if (router.currentRoute.value.fullPath.indexOf('addSupplier') !== -1) {
      router.push('/home/index')
    } else if (router.currentRoute.value.fullPath.indexOf('researchAddSupplierClassAdd') !== -1) {
      router.push('/researchAddSupplierClass')
    } else if (router.currentRoute.value.fullPath.indexOf('researchAddSupplierClass') !== -1) {
      router.push('/researchAddSupplier')
    } else if (router.currentRoute.value.fullPath.indexOf('researchAddSupplier') !== -1) {
      router.push('/research/researchPage')
    } else if (router.currentRoute.value.fullPath.indexOf('inboundGoods') !== -1) {
      // 入库选择商品回退
      router.push({
        path: '/addArehousing',
        query: {
          index: route.query.index
        }
      })
    } else if (router.currentRoute.value.fullPath.indexOf('transferProductList') !== -1) {
      router.push({
        path: '/allocation',
      })
    } else if (router.currentRoute.value.fullPath == '/productHome/examineApprove') {
      // 产品部审批数据
      router.push('/productHome/productMine')
    } else if (router.currentRoute.value.fullPath.indexOf('examineApproveDetail') !== -1) {
      // 产品部补样邀约列表
      router.push('/productHome/examineApprove')
    } else if (router.currentRoute.value.fullPath == '/supplyInvitation') {
      // 运营部补样邀约
      router.push('/operation/operatepage')
    } else if (router.currentRoute.value.fullPath == '/supplyInvitationDetail') {
      // 运营部补样邀约详情
      router.push('/supplyInvitation')
    } else if (router.currentRoute.value.fullPath == '/operationApproval') {
      // 运营部补样审批列表
      router.push('/operation/operateMine')
    } else if (router.currentRoute.value.fullPath == '/operationApprovalDetails') {
      // 运营部补样审批列表详情
      router.push('/operationApproval')
    }


    else {
      router.back()
    }
  }
  /** 断网重连刷新 */
  if (arg.action == 'refreshPage') {
    window.location.reload()
  }
  /** 当前基座版本号 */
  if (arg.action == 'phoneVersion') {
    localStorage.setItem("phoneVersion", arg.version);
  }
  if (arg.action == 'zxmassge') {
    let lx = ''
    if (user.value[0].indexOf('recruit') != -1) {
      // 招商部
      lx = '招商部'
    } else if (user.value[0].indexOf('superadmin') != -1) {
      // 超级管理员
      lx = '超级管理员'
    } else if (user.value[0].indexOf('stock') != -1) {
      // 产品
      lx = '产品部'
    } else if (user.value[0].indexOf('core') != -1) {
      // 运营
      lx = '运营部'
    } else if (user.value[0].indexOf('invent') != -1) {
      // 研发
      lx = '研发部'
    } else if (user.value[0].indexOf('selectionOfficer') != -1) {
      // 选品官
      lx = '选品官'
    } else if (user.value[0] == "app") {
      // app
    }
    router.push({
      path: `/notice`,
      query: {
        type: lx,
        dept: arg.type
      }
    });
  }
}
</script>

<style lang="less" scoped>
.update {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bg-white-height {
  height: 44px;
  width: 100%;
  background: #fff;
  position: relative;
  z-index: 1000;
}

:deep(.van-nav-bar__content) {
  background-color: #fff;
  height: 46px !important;
  width: 100%;
}

:deep(.van-nav-bar__title) {
  padding: 5px;
  font-size: 16px !important;
  z-index: 999 !important;
  color: #1a1b1c;
}


:deep(.van-nav-bar__left .van-icon) {
  color: #1a1b1c !important;
}

:deep(.svg-icon) {
  width: 21.39px !important;
  height: 19.1px !important;
}

:deep(.van-tabbar-item__text) {
  font-weight: 400;
  font-size: 11px;
}

:deep(.van-field__label) {
  // font-size: 14px !important;
  color: #1a1b1c !important;
}

.home_loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
}

.is_home_loading {
  display: none;
}
</style>
